# Copyright (c) 2024 Huawei Technologies Co., Ltd.
#
# openMind is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#
#          http://license.coscl.org.cn/MulanPSL2
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.

import json
import os
from datetime import datetime

from openmind_hub.plugins.openmind.om_api import LastCommitInfo, RepoFile, RepoFolder

file_path = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(file_path, "public_address_lib.json"), encoding="utf-8") as cfg_file:
    json_file = cfg_file.read()
    UPLOAD1 = json.loads(json_file)["upload1_url"]
    UPLOAD2 = json.loads(json_file)["upload2_url"]
    VERIFY_URL = json.loads(json_file)["verify_url"]
    ENDPOINT_SH = json.loads(json_file)["endpoint_sh_url"]
    FAKE_LOCATION = json.loads(json_file)["fake_location_url"]
    EXPECTED_URL = json.loads(json_file)["expected_url"]
    EXPECTED_SH_URL = json.loads(json_file)["expected_sh_url"]
    MISSING_REPO_URL = json.loads(json_file)["missing_repo_url"]
    CLONE_FROM = json.loads(json_file)["clone_from_url"]
    PRE_UPLOAD_URL = json.loads(json_file)["pre_upload_url"]
    ENDPOINT_URL = json.loads(json_file)["endpoint_url"]
    REMOTE_URL = json.loads(json_file)["remote_url"]
    TEST_URL = json.loads(json_file)["test_url"]
    EXAMPLE_URL = json.loads(json_file)["example_url"]


FAKE_REPO = {
    "data": {
        "created_at": "string",
        "desc": "string",
        "download_count": 0,
        "fullname": "string",
        "id": "string",
        "labels": {"frameworks": ["string"], "license": "string", "others": ["string"], "task": "string"},
        "like_count": 0,
        "name": "string",
        "owner": "owner",
        "updated_at": "string",
        "visibility": "string",
    }
}
FAKE_MODELS = {
    "data": {
        "models": [
            {
                "id": "41",
                "name": "name",
                "desc": "",
                "task": "",
                "owner": "owner",
                "fullname": "",
                "updated_at": 1706235731,
                "like_count": 0,
                "download_count": 0,
            }
        ],
        "total": 1,
    }
}
FAKE_DATASETS = {
    "data": {
        "datasets": [
            {
                "id": "44",
                "name": "name",
                "desc": "",
                "task": "",
                "owner": "owner",
                "fullname": "",
                "updated_at": 1706235731,
                "like_count": 0,
                "download_count": 0,
            }
        ],
        "total": 1,
    }
}
FAKE_SPACES = {
    "data": {
        "spaces": [
            {
                "id": "43",
                "name": "name",
                "desc": "",
                "task": "",
                "owner": "owner",
                "fullname": "",
                "updated_at": 1706235731,
                "like_count": 0,
                "download_count": 0,
            }
        ],
        "total": 1,
    }
}
FAKE_METRICS = {
    "data": [
        {
            "id": "42",
            "spaceId": "space_id",
            "desc": "",
        }
    ],
}
FAKE_REPO_TREE = {
    "data": {
        "tree": [
            {
                "path": "123.txt",
                "type": "file",
                "size": 17,
                "is_lfs": "false",
                "etag": "80457db11003b2eb26502ab93ea29e29ffd86d24",
                "commit": {"commit_sha": "123456", "created": "2024-03-19T19:11:43+08:00", "message": "commit message"},
            },
            {
                "path": "folder",
                "type": "dir",
                "size": 0,
                "is_lfs": "false",
                "etag": "8f83d649e7c5ecbcf1eed51c61fecff51b395d11",
                "commit": {"commit_sha": "123456", "created": "2024-03-19T19:11:43+08:00", "message": "commit message"},
            },
        ]
    }
}
FAKE_SPACE_RUNTIME = {
    "stage": "BUILDING",
    "hardware": {"current": "CPU basic 2 vCPU · 4GB · FREE"},
    "gcTimeout": 100,
    "storage": "small",
}
FILE_OBJ = RepoFile(
    path="a/b",
    is_lfs=False,
    commit={"created": "2024-03-19T19:11:43+08:00", "commit_sha": "123", "message": "123"},
)
FOLDER_OBJ = RepoFolder(
    path="a",
    commit={"created": "2024-03-19T19:11:43+08:00", "commit_sha": "123", "message": "123"},
)
FILE_INFO = {
    "name": "models/user/repo/a/b",
    "size": 0,
    "type": "file",
    "blob_id": "",
    "lfs": None,
    "last_commit": LastCommitInfo(oid="123", title="123", date=datetime(2024, 3, 19, 19, 11, 43)),
}
FOLDER_INFO = {
    "name": "models/user/repo/a",
    "size": 0,
    "type": "directory",
    "last_commit": LastCommitInfo(oid="123", title="123", date=datetime(2024, 3, 19, 19, 11, 43)),
}
